<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>数据源信息导入</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${ctx}/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="${ctx}/systemStatic/style/admin.css">
    <link rel="stylesheet" href="${ctx}/iconfont/iconfont.css"/>
    <link rel="stylesheet" href="${ctx}/css/public.css">
    <script type="text/javascript">
        var __ctx = "${ctx}";
    </script>
</head>
<body>

<form class="layui-form" action="" style="padding: 10px 75px;">
    <div class="layui-upload-drag" type="file" name="xmlFile" id="xmlFile">
        <i class="layui-icon"></i>
        <p>点击上传，或将文件拖拽到此处</p>
    </div>
    <div class="layui-btn-container layui-footer" style="position: absolute;left:37%;bottom:0">
        <button type="button" class="layui-btn layui-btn-sm" id="importButton">导入</button>
        <button class="layui-btn layui-btn-sm layui-btn-danger" type="button" id="return">取消</button>
    </div>
</form>
<script src="${ctx}/public/component.js" type="text/javascript"></script>
<script src="${ctx}/layui/layui.js"></script>
<script>
    layui.config({
        base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index','element', 'upload', 'jquery','publicMethods'], function () {
        var element = layui.element;
        var upload = layui.upload;
        var $ = layui.$;
        var setter = layui.setter;
        var layer = layui.layer;
        var publicMethods = layui.publicMethods;
        //关闭弹窗
        var index = parent.layer.getFrameIndex(window.name);
        $('#return').click(function () {
            parent.layer.close(index);
        });
        //指定允许上传的文件类型
        upload.render({
            elem: '#xmlFile'
            , url: serverPath.systemPath + '/qbdms/wFadongji/importData'
            , accept: 'file'
            , multiple: true
            , auto: false //选择文件后不自动上传
            , bindAction: '#importButton' //指向一个按钮触发上传
            , before: function (obj) {
                obj.preview(function (index, file, result) {
                    var name = file.name//file表示文件信息，result表示文件src地址
                    var index = name.lastIndexOf('.');
                    name = name.substring(index + 1, name.length);
                    if (name != 'xlsx' && name != 'xls') {
                        layer.alert('请选择excel文件进行导入',{title: false,skin: 'confirm-class'});
                        return false;
                    }
                });
            }
            , done: function (res, upload) {
                console.log(res);
                if (res.code == 1) {
                    window.parent.layer.alert(res.msg);
                } else {
                    layer.alert(publicMethods.confirmStyle(res.msg),{title: false,skin: 'confirm-class'}, function () {
                        parent.layer.close(index);
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                        parent.layui.table.reload('wFadongjiTable');
                        parent.layui.totalFilter.init('wFadongjiTable');

                        parent.window.Initialization();
                    });
                }
            },
            error:function(){
                console.log(3)
            }
        });
    });
</script>
</body>
</html>